﻿/*
* Copyright (C) 2020 ~ 2024 chaigec All Rights Reserved.
*
* Author:     chaigec <chaigec@163.com>
* Maintainer: chaigec <chaigec@163.com>

 * Use of this source code is governed by MIT license that can be found in the
 * LICENSE file in the root of the source tree. All contributing project authors
 * may be found in the AUTHORS file in the root of the source tree.
*/

#ifndef MK_THREAD_H
#define MK_THREAD_H
#include "MkUtil/MkTypes.h"

typedef MkFunction<void()> ThreadFun;
class MkApi CMkThread
{
public:
    CMkThread();
    virtual ~CMkThread();
public:
    Uint32 Start(ThreadFun Func);
    void Stop();
    Uint32 GetCurrentId() { return m_ThreadId; }

    static void ThreadSleep(Uint32 dwMilliseconds);
protected:
#ifdef _WIN32
    static unsigned int __stdcall Thread(void *lParam);
#else
    static void *threadrun(void *lParam);
#endif
private:
#ifdef _WIN32
    HANDLE  m_ThreadHandle;
#else
    pthread_t m_ThreadHandle;
#endif
    ThreadFun  m_Fun;
    Uint32     m_ThreadId;
};








#endif
